﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace dmp_ui_demo
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            comboBox1.DataSource = Enum.GetValues(typeof(BrandNameType));
            comboBox1.FormatString = "F";
            comboBox1.SelectedItem = BrandNameType.中文商标名;

            textBox1.GotFocus += textBox1_GotFocus;
            textBox1.LostFocus += textBox1_LostFocus;
        }

        void textBox1_LostFocus(object sender, EventArgs e)
        {
            Debug.WriteLine("LostFocus");
        }

        void textBox1_GotFocus(object sender, EventArgs e)
        {
            Debug.WriteLine("GotFocus");
        }

        private void comboBox1_Validating(object sender, CancelEventArgs e)
        {
            var self = sender as ComboBox;
            var value = (BrandNameType)self.SelectedValue;
            if (value == BrandNameType.无)
            {
                e.Cancel = true;
                return;
            }
        }

        private void textBox1_Validating(object sender, CancelEventArgs e)
        {
            Debug.WriteLine("Validating");
            var self = sender as TextBox;
            if (string.IsNullOrEmpty(self.Text))
            {
                e.Cancel = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var val = this.ValidateChildren();
        }

        private void textBox1_Enter(object sender, EventArgs e)
        {
            Debug.WriteLine("Enter");
        }

        private void textBox1_Leave(object sender, EventArgs e)
        {
            Debug.WriteLine("Leave");
        }

        private void textBox1_Validated(object sender, EventArgs e)
        {
            Debug.WriteLine("Validated");
        }

        private void textBox2_Validating(object sender, CancelEventArgs e)
        {

        }
    }
}
